package com.fstec.ks.master.dao.jdbc.extractor;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;

import com.fstec.ks.master.vo.ExamServerVO;

/**
 * 考试服务器信息字段Extractor类
 * @Title ExamServerExtractor.java
 * @Package com.fstec.ks.master.dao.jdbc.extractor
 * @Description 
 * Copyright: Copyright (c) 2017
 * Company:北京信诺软通
 *
 * @author <a href="mailto:zhkuqijin@163.com">谢启进</a>
 * @date 2023年10月06日 下午14:37:34
 * @version V1.0
 */
public class ExamServerExtractor implements ResultSetExtractor<List<ExamServerVO>> {
	/**
	 * 查询字段
	 * 
	 * @return
	 * @auth <a href="mailto:liyunfeng@sinotn.com">李云峰</a>
	 * @date 2017年3月6日 下午3:27:25
	 */
	public static String getColumns() {
		return "id,backup_time,exam_server_name,ip_addr,server_port,room_count,reg_time,last_conn_time,server_status,client_open_count";
	}

	/*
	 * @see org.springframework.jdbc.core.ResultSetExtractor#extractData(java.sql.ResultSet)
	 */
	@Override
	public List<ExamServerVO> extractData(ResultSet rs) throws SQLException, DataAccessException {
		ArrayList<ExamServerVO> list = new ArrayList<ExamServerVO>();
		ExamServerVO vo = null;
		long l;
		while(rs.next()) {
			vo = new ExamServerVO();
			vo.setId(rs.getString(1));
			l=rs.getLong(2);
			if(l>0){
				vo.setBackupTime(new Date(l));
			}
			vo.setExamServerName(rs.getString(3));
			vo.setIpAddr(rs.getString(4));
			vo.setServerPort(rs.getString(5));
			vo.setRoomCount(rs.getInt(6));
			l=rs.getLong(7);
			if(l>0){
				vo.setRegTime(new Date(l));
			}
			l=rs.getLong(8);
			if(l>0){
				vo.setLastConnTime(new Date(l));
			}
			vo.setServerStatus(rs.getByte(9));
			vo.setClientOpenCount(rs.getInt(10));
			list.add(vo);
		}
		return list;
	}
}
